package com.cxl.aop;

import com.cxl.ann.LogAnn;
import lombok.extern.java.Log;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author: 20971
 * @time: 2022/3/16 9:39
 * @description:
 */
@Component
@Aspect
@Log
public class LogAop {

    @Around("@annotation(logAnn)")
    public Object around(ProceedingJoinPoint joinPoint, LogAnn logAnn) {
        Object value = null;
        try {
            log.info("前置通知");
            value = joinPoint.proceed();
            String s = logAnn.value();
            log.info("后置通知+参数"+s);
        } catch (Throwable e) {
            log.info("异常通知");
            e.printStackTrace();
        }finally {
            log.info("最终通知");
        }
        return value;
    }
}
